package com.css.fxfzxczh.modules.seismicIntensityMap.seismicIntensityMapData.service.impl;

import com.css.fxfzxczh.base.attachment.service.AttachmentInfoService;
import com.css.fxfzxczh.common.utils.UpdateUtil;
import com.css.fxfzxczh.modules.disasterSituationDataManage.houMonData.entity.HouMonDataVo;
import com.css.fxfzxczh.modules.disasterSituationDataManage.samPoiData.entity.SamPoiData;
import com.css.fxfzxczh.modules.seismicIntensityMap.seismicIntensityMapData.entity.SeiIntMapData;
import com.css.fxfzxczh.modules.seismicIntensityMap.seismicIntensityMapData.queryParams.QueryParams;
import com.css.fxfzxczh.modules.seismicIntensityMap.seismicIntensityMapData.repository.SeiIntMapDataRepository;
import com.css.fxfzxczh.modules.seismicIntensityMap.seismicIntensityMapData.service.SeiIntMapDataService;
import com.css.fxfzxczh.modules.seismicIntensityMap.seismicIntensityMapData.vo.SeiIntMapDataVo;
import com.css.fxfzxczh.modules.synthesizeInfoManage.earEveManage.entity.EarEveManage;
import com.css.fxfzxczh.modules.synthesizeInfoManage.earEveManage.repository.EarEveManageRepository;
import com.css.fxfzxczh.util.PlatformObjectUtils;
import com.css.fxfzxczh.util.UUIDGenerator;
import com.css.fxfzxczh.web.PlatformSessionContext;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

@Service
public class SeiIntMapDataServiceImpl implements SeiIntMapDataService {
    @Resource
    SeiIntMapDataRepository seiIntMapDataRepository;

    @Resource
    AttachmentInfoService attachmentInfoService;

    @Resource
    EarEveManageRepository earEveManageRepository;

    /*@Override
    public Map<String, Object> getPage(int curPage, int pageSize,String eventName) {
        Map<String, Object> map=seiIntMapDataRepository.getPage(curPage, pageSize, eventName);
        List<SeiIntMapDataVo> rows = (List<SeiIntMapDataVo>) map.get("rows");
        for(SeiIntMapDataVo item:rows){
            if (PlatformObjectUtils.isNotEmpty(item.getExpertOpinionPdf())){
                item.setExpertOpinionPdfAtt(attachmentInfoService.queryFile(item.getExpertOpinionPdf()));
            }
            if (PlatformObjectUtils.isNotEmpty(item.getSeismicIntensityMap())){
                item.setSeismicIntensityMapAtt(attachmentInfoService.queryFile(item.getSeismicIntensityMap()));
            }
            if (PlatformObjectUtils.isNotEmpty(item.getExpertOpinionPdf())){
                item.setProcessMaterialsAtt(attachmentInfoService.queryFile(item.getExpertOpinionPdf()));
            }
        }
        return map;
    }*/

    @Override
    public List<SeiIntMapDataVo> getTable(String xsemId) {
        List<SeiIntMapDataVo> list = new ArrayList<>();
        EarEveManage earEveManage = earEveManageRepository.findById(xsemId);
        SeiIntMapData seiIntMapData = seiIntMapDataRepository.findByXsemId(xsemId);
        SeiIntMapDataVo seiIntMapDataVo=new SeiIntMapDataVo();
        seiIntMapDataVo.setXsemId(xsemId);
        seiIntMapDataVo.setEventCode(earEveManage.getEventCode());
        seiIntMapDataVo.setEventName(earEveManage.getEventName());
        if(!PlatformObjectUtils.isEmpty(seiIntMapData)){
            UpdateUtil.copyNullProperties(seiIntMapData, seiIntMapDataVo);
            if (PlatformObjectUtils.isNotEmpty(seiIntMapData.getExpertOpinionPdf())){
                seiIntMapDataVo.setExpertOpinionPdfAtt(attachmentInfoService.queryFile(seiIntMapData.getExpertOpinionPdf()));
            }
            if (PlatformObjectUtils.isNotEmpty(seiIntMapData.getSeismicIntensityMap())){
                seiIntMapDataVo.setSeismicIntensityMapAtt(attachmentInfoService.queryFile(seiIntMapData.getSeismicIntensityMap()));
            }
            if (PlatformObjectUtils.isNotEmpty(seiIntMapData.getProcessMaterials())){
                seiIntMapDataVo.setProcessMaterialsAtt(attachmentInfoService.queryFile(seiIntMapData.getProcessMaterials()));
            }
        }

        list.add(seiIntMapDataVo);
        return list;
    }

    @Override
    public void save(SeiIntMapData seiIntMapData) {
        SeiIntMapData byXsemId=seiIntMapDataRepository.findByXsemId(seiIntMapData.getXsemId());
        if(PlatformObjectUtils.isNotEmpty(byXsemId)){
            seiIntMapData.setId(byXsemId.getId());
            seiIntMapDataRepository.update(seiIntMapData);
        }else {
            seiIntMapData.setId(UUIDGenerator.getUUID());
            seiIntMapDataRepository.save(seiIntMapData);
        }

    }
}
